package com.youku.plugins.liveLoader.view
{
   import flash.display.MovieClip;
   import com.youku.interfaces.IPlayerProxy;
   import flash.display.Loader;
   import flash.events.Event;
   import flash.events.IOErrorEvent;
   import flash.events.SecurityErrorEvent;
   import com.youku.events.PlayerControlEvent;
   import flash.net.URLRequest;
   import flash.display.LoaderInfo;
   
   public class LiveLoaderMediator extends Object
   {
      
      public function LiveLoaderMediator(param1:MovieClip, param2:IPlayerProxy) {
         super();
         this._mainMc = param1;
         this._playerProxy = param2;
         this.init();
      }
      
      private var _mainMc:MovieClip;
      
      private var _playerProxy:IPlayerProxy;
      
      private var _loader:Loader;
      
      private var _player;
      
      private var _data:Object;
      
      private function init() : void {
         this._loader = new Loader();
         this._loader.contentLoaderInfo.addEventListener(Event.COMPLETE,this.onLoadComplete);
         this._loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,this.onLoadError);
         this._loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR,this.onLoadError);
         this._playerProxy.addEventListener(PlayerControlEvent.ADD_LIVE_PLAYER,this.loadLivePlayer);
      }
      
      private function loadLivePlayer(param1:PlayerControlEvent) : void {
         if(this._player != null)
         {
            return;
         }
         this._data = {};
         this._data.liveid = param1.data.liveid;
         this._data.p2p = 1;
         this._data.isAutoPlay = "true";
         this._loader.load(new URLRequest(this._playerProxy.rootGetData.rootBaseURL + "/" + "livetest.swf"));
      }
      
      private function onLoadComplete(param1:Event) : void {
         this._player = (param1.target as LoaderInfo).loader.content;
         try
         {
            this._player.visible = false;
            this._mainMc.addChild(this._player);
            this._player.init(this._data);
            this._player.setVolume(0);
            this._player.setSize(200,200);
         }
         catch(error:Error)
         {
         }
      }
      
      private function onLoadError(param1:Event) : void {
      }
   }
}
